package com.shanghai.shanghaielectric.UI.refreshView;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shanghai.shanghaielectric.R;

import java.io.File;
import java.util.List;

import shanghaielectric_lib.Utils.MySystemUtil;


/**
 * Created by wnw on 16-5-26.
 */
public class MyAdapter_updateAPP extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    //定义一个集合，接收从Activity中传递过来的数据和上下文
    private String[] mApp_names;
    private String[] mCreatTimes;
    private Context mContext;
    private List<File> mFiles;

    //    public MyAdapter_updateAPP(Context context, String[] app_names,String [] creatTimes) {
//        this.mContext = context;
//        this.mApp_names = app_names;
//        this.mCreatTimes=creatTimes;
//    }
    public MyAdapter_updateAPP(Context context, List files) {
        this.mContext = context;
        this.mFiles = files;
    }

    @Override
    public int getItemCount() {
        return mFiles.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.updateapp_item, parent, false);

        return new MyHolder(layout);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
//            String name = mApp_names[position];
//            String time=mCreatTimes[position];
            final File file = mFiles.get(position);
            String name=file.getName();
            ((MyHolder) holder).file_name.setText(file.getName());
            ((MyHolder) holder).file_ctreaTime.setText(MySystemUtil.formatLong2StringTime(file.lastModified()));


            ((MyHolder) holder).item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
//                    Toast.makeText(mContext, "点击了", Toast.LENGTH_SHORT).show();

                    MySystemUtil.installAPK(mContext, file);
                }
            });
        }
    }

    class MyHolder extends RecyclerView.ViewHolder {

        TextView file_name, file_ctreaTime;
        View item;

        public MyHolder(View itemView) {
            super(itemView);
            file_name = (TextView) itemView.findViewById(R.id.file_name);
            file_ctreaTime = (TextView) itemView.findViewById(R.id.file_ctreaTime);
            item = (View) itemView.findViewById(R.id.update_App_item);

        }
    }

//    public void setData(ErrorInfoModel errorInfoModel){
//        mList.add(0,errorInfoModel);
//    }

}